package breadbox.dataManagement;

import java.io.IOException;
import java.util.concurrent.BlockingQueue;

import breadbox.pastry.ID;
import breadbox.pastry.LongID;
import breadbox.pastry.Message;

public abstract class ReplicationManager extends Thread {

	protected Manager manager;
	protected Storage storage;
	
	public ReplicationManager(Manager m) {
		//initialize data structure for keeping track of replicated chunks
		manager = m;
		storage = m.getStorage();
	}
	
	public abstract void replicate(byte[] data, ID id);
	public abstract void replicateDelete(ID id);

	public abstract void run();
}
	/*
	public void run() {
		byte[] data;
		while(true) {
			try {
				while(!replicationQueue.isEmpty()) {
					//this will block until there is an element in the queue
					ReplicationMessage rm = replicationQueue.take();
					ID id = rm.id;
					switch(rm.type) {
						case ADD: {
							try {
								data = storage.get(id);
								replicate(data, id);
							}
							catch(IOException e) { }
							break;
						}
						case DELETE: {
							replicateDelete(id);
							break;
						}
						default: {
							return;
						}		
					}
				}
			}
			catch(InterruptedException e) {}
		}
	}
	
	//used to store the replication message
	//used internally, not to be confused with the Pastry message
	public static class ReplicationMessage {
		
		public ReplicationMessage(ID i, ReplicationType t) {
			id = i;
			type = t;
		}
		protected ID id;
		protected ReplicationType type;
		
		public static enum ReplicationType {
			ADD, DELETE,
		}
	}
}
*/